// vite.config.ts
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'

export default defineConfig({
  server: {
    proxy: {
      // '/api': {
      //   target: 'http://localhost:8888',
      //   changeOrigin: true,
      //   rewrite: path => path.replace(/^\/api/, ''),
      //   configure: proxy => {
      //     // 放宽 http-proxy-middleware 的 bodyLimit
      //     // @ts-ignore
      //     proxy.options.bodyLimit = '10mb'
      //   },

      // },
      '/Customer': {
        target: 'http://localhost:8083',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/Customer/, '/Customer')
      },
      '/Provider': {
        target: 'http://localhost:8083',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/Provider/, '/Provider')
      },
      '/Account': {
        target: 'http://localhost:8083',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/Account/, '/Account')
      },
      '/purchaseInvoice': {
        target: 'http://localhost:8087',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/purchaseInvoice/, '/purchaseInvoice')
      },
      '/counter': {
        target: 'http://localhost:8085',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/counter/, '/counter')
      },
      // '/good': {
      //   target: 'http://localhost:8083',
      //   changeOrigin: true,
      //   rewrite: path => path.replace(/^\/good/, '/good')
      // },
      '/inStore': {
        target: 'http://localhost:8089',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/inStore/, '/inStore')
      }
    }
  },
  plugins: [
    vue(),
    vueJsx(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
